#pragma once

#include "Callback.h"
#include "ValueKey.h"

using namespace AT;

class CThreadpool;

class COrderedTask
{
public:
	COrderedTask();
	~COrderedTask();

	bool Init();
	void Exit();
	bool PostTask(const CValueKey& key, ICallbackPtr&& pTask, const std::unique_ptr<CThreadpool>& pThreadpool);

private:
	void RunTask(const CValueKey& key);

	class CTaskQueue
	{
	public:
		CTaskQueue() = default;
		CTaskQueue(const CTaskQueue&) = delete;
		CTaskQueue& operator=(const CTaskQueue&) = delete;

		bool bRunning = false;
		std::deque<ICallbackPtr> deqTasks;
	};

	SRWLOCK m_SRWLock = SRWLOCK_INIT;
	std::unordered_map<CValueKey, CTaskQueue> m_mapTaskQueues;
};
